package com.ai.ly.goodsautocat.vo;

import java.util.HashMap;
import java.util.Map;

public class SampleMapHolder<T,E> {

    private Map<T,E> trainningSampleMap=new HashMap<>();
    
    private Map<T,E> testSampleMap=new HashMap<>();
    
    /**测试样本数所占的比例*/
    private double testSampleRatio;
    
    public SampleMapHolder(double testSampleRatio) throws Exception {
        if (testSampleRatio<0||testSampleRatio>1) {
            throw new Exception("testSampleRatio can not be less than 0 or larger than 1");
        }
        this.testSampleRatio=testSampleRatio;
    }
    
    public void addSample(T key,E sample) {
        double p=Math.random();
        if (p<testSampleRatio) {
            testSampleMap.put(key, sample);
            return;
        }
        trainningSampleMap.put(key, sample);
    }

    public Map<T,E> getTrainningSampleMap() {
        return trainningSampleMap;
    }

    public Map<T,E> getTestSampleMap() {
        return testSampleMap;
    }

}
